@echo off
chcp 65001 >nul
echo 开始批量更新模板文件...

REM 定义模板文件目录
set TEMPLATES_DIR=src\main\resources\templates

REM 备份原始文件
echo 备份原始文件...
set BACKUP_DIR=%TEMPLATES_DIR%_backup_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set BACKUP_DIR=%BACKUP_DIR: =0%
xcopy "%TEMPLATES_DIR%" "%BACKUP_DIR%" /E /I /Y

echo 更新模板文件...

REM 使用PowerShell进行批量替换
powershell -Command "Get-ChildItem -Path '%TEMPLATES_DIR%' -Filter '*.html' -Recurse | ForEach-Object { (Get-Content $_.FullName) -replace '<link href=\"https://cdn\.jsdelivr\.net/npm/bootstrap@5\.1\.3/dist/css/bootstrap\.min\.css\" rel=\"stylesheet\">', '<link rel=\"stylesheet\" th:href=\"@{/lib/bootstrap/css/bootstrap.min.css}\">' | Set-Content $_.FullName }"

powershell -Command "Get-ChildItem -Path '%TEMPLATES_DIR%' -Filter '*.html' -Recurse | ForEach-Object { (Get-Content $_.FullName) -replace '<link href=\"https://cdn\.jsdelivr\.net/npm/bootstrap-icons@1\.7\.2/font/bootstrap-icons\.css\" rel=\"stylesheet\">', '<link rel=\"stylesheet\" th:href=\"@{/lib/bootstrap-icons/font/bootstrap-icons.css}\">' | Set-Content $_.FullName }"

powershell -Command "Get-ChildItem -Path '%TEMPLATES_DIR%' -Filter '*.html' -Recurse | ForEach-Object { (Get-Content $_.FullName) -replace '<script src=\"https://cdn\.jsdelivr\.net/npm/bootstrap@5\.1\.3/dist/js/bootstrap\.bundle\.min\.js\"></script>', '<script th:src=\"@{/lib/bootstrap/js/bootstrap.bundle.min.js}\"></script>' | Set-Content $_.FullName }"

powershell -Command "Get-ChildItem -Path '%TEMPLATES_DIR%' -Filter '*.html' -Recurse | ForEach-Object { (Get-Content $_.FullName) -replace '<script src=\"https://cdn\.jsdelivr\.net/npm/chart\.js\"></script>', '<script th:src=\"@{/lib/npm/chart.js}\"></script>' | Set-Content $_.FullName }"

echo.
echo 模板文件更新完成！
echo.
echo 已更新的文件：
for /r "%TEMPLATES_DIR%" %%f in (*.html) do echo - %%f
echo.
echo 备份文件位置：
echo - %BACKUP_DIR%
echo.
echo 更新内容：
echo - Bootstrap CSS: CDN -^> 本地 /lib/bootstrap/css/bootstrap.min.css
echo - Bootstrap Icons: CDN -^> 本地 /lib/bootstrap-icons/font/bootstrap-icons.css
echo - Bootstrap JS: CDN -^> 本地 /lib/bootstrap/js/bootstrap.bundle.min.js
echo - Chart.js: CDN -^> 本地 /lib/npm/chart.js
pause 